//
//  ExLoadPDFViewController.m
//  OC-Example
//
//  Created by apang on 2018/7/31.
//  Copyright © 2018年 apang.men All rights reserved.
//

#import "ExLoadPDFViewController.h"

@interface ExLoadPDFViewController ()
@property (nonatomic, strong) UIWebView * webView;
@end

@implementation ExLoadPDFViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self.view setBackgroundColor:[UIColor whiteColor]];

    self.title = @"读取PDF文件";

    _webView = [[UIWebView alloc] init];
    [_webView setTranslatesAutoresizingMaskIntoConstraints:NO];
    [self.view addSubview:_webView];
    if (@available(iOS 11.0, *)) {
        _webView.scrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }

    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-(0)-[_webView]-(0)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_webView)]];
    [self.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-(0)-[_webView]-(0)-|" options:0 metrics:nil views:NSDictionaryOfVariableBindings(_webView)]];

    [_webView sizeToFit];

    [_webView setScalesPageToFit:YES];
}

-(void)viewWillAppear:(BOOL)animated{

    [super viewWillAppear:animated];

    NSString * filePath = [[NSBundle mainBundle] pathForResource:@"PopinSwift" ofType:@"pdf" inDirectory:@"Resource/Document"];

    NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL fileURLWithPath:filePath]];

//    NSURLRequest * request = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://ww.cpad.gov.cn/module/download/downfile.jsp?filename=1608230915130896498.doc&classid=0"]];

    [_webView loadRequest:request];


}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
